import Vue from 'vue';
import iView from 'iview';
import {router} from './router/index';
import {appRouter} from './router/router';
import store from './store';
import App from './app.vue';
import '@/locale';
import 'iview/dist/styles/iview.css';
import './styles/iconfont.less';
import VueI18n from 'vue-i18n';
import Init from './libs/Init';
import zh from 'iview/dist/locale/zh-CN';
import permission from '@/libs/permission';

import padLeft from '@/libs/padLeft.js'
Vue.use(padLeft);

Vue.router = router;
Vue.use(permission);
Vue.use(VueI18n);
Vue.use(iView);
Vue.config.lang = 'zh-CN';
Vue.locale('zh-CN', zh);

Init.build(Vue,router,store);

new Vue({
  el: '#app',
  router: router,
  store: store,
  render: h => h(App),
  data: {
    currentPageName: ''
  },
  mounted () {
    this.currentPageName = this.$route.name;
    this.$store.commit('initCachepage');
  },
  created () {
    let tagsList = [];
    appRouter.map((item) => {
      if (item.children.length <= 1) {
        tagsList.push(item.children[0]);
      } else {
        tagsList.push(...item.children);
      }
    });
    this.$store.commit('setTagsList', tagsList);
  }
});
